from django.contrib.auth.models import User
from django.db import models


# Create your models here.

class BaseModel(models.Model):
    created_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
    last_modified = models.DateTimeField(auto_now=True, verbose_name='更新时间')

    class Meta:
        abstract = True

# 区域模型类
class Area(BaseModel):
    name = models.CharField(max_length=200, verbose_name='名称')

    class Meta:
        verbose_name = '区域'
        verbose_name_plural = '区域'

    def __str__(self):
        return self.name

# 任务模型类
class Task(BaseModel):
    title = models.CharField(max_length=200, verbose_name='标题')
    description = models.TextField(verbose_name='描述')
    start_time = models.DateTimeField(verbose_name='开始时间')
    end_time = models.DateTimeField(verbose_name='结束时间')
    num = models.IntegerField(verbose_name='任务数量')
    area = models.ForeignKey(Area, on_delete=models.CASCADE, verbose_name='区域')
    # 任务发布者（银行客户经理或管理员）
    manager = models.ForeignKey(User, related_name='manager_id',
                                on_delete=models.CASCADE, verbose_name='发布者')
    # 任务执行者（业务员）
    executor = models.ForeignKey(User, related_name='executor_id',
                                 on_delete=models.CASCADE, verbose_name='执行者')

    class Meta:
        verbose_name = '任务'
        verbose_name_plural = '任务'

    def __str__(self):
        return self.title
